package dryven.view.engine.component.metadata;

import java.lang.reflect.Method;

import dryven.view.engine.component.MultiThreadViewComponent;

public class MultiThreadRenderMethodDiscoverer {
	public Method getRenderMethod(Class<? extends MultiThreadViewComponent> componentClass) {
		Method renderComponentMethod = null;
		Class<?> clazz = componentClass;
		do {
			for (Method m : clazz.getDeclaredMethods()) {
				if(m.getName().equals("renderComponent")) {
					renderComponentMethod = m;
					break;
				}
			}
			clazz = clazz.getSuperclass();
		} while(!clazz.equals(MultiThreadViewComponent.class) && renderComponentMethod==null);
		if(renderComponentMethod==null) {
			throw new RuntimeException("You need to implement a method called renderComponent in the component "+getClass().getName());
		}
		return renderComponentMethod;
	}
}
